package com.ctrip.ec.biz.dao.album;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.album.AlbumImageEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.IdConvert;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class AlbumImageDao extends DaoBase<AlbumImageEntity> {
    public AlbumImageDao() {
        super(AlbumImageEntity.class);
    }
    public AlbumImageDao(DbAccess db) {
        super(AlbumImageEntity.class,db);
    }

    public List<Long> getImageIds(List<Long> ids) throws SQLException {
        String sql = "select image_id from "  + this.getTableName() + " where id in ("  + IdConvert.join(ids) + ")";
        List<Long>  imageIds = this.db.query(Long.class, sql);
        return imageIds;
    }

    public void deleteByAlbumIds(List<Long> ids) throws SQLException {
        if(ids != null && ids.size()>0) {
            String strIds = IdConvert.join(ids);
            String sql = "delete from " + this.getTableName() + " where album_id in (" + strIds+ ")";
            this.db.execute(sql);
        }
    }
}
